﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Framework;

namespace Business.Operations
{
    public class IlceOperation
    {
        private static HPDMASEntities db = new HPDMASEntities();

        public IlceOperation()
        {

        }

        public static List<Ilce> IlceGetAll()
        {
            var ilceColumn = db.Ilce.ToList();
            return ilceColumn;
        }

        public static IEnumerable<Ilce> IlceGetByIlceId(int ilceId)
        {
            var ilceColumn = (from c in db.Ilce where c.IlceID == ilceId select c);
            return ilceColumn;
        }

        /// <summary>
        /// Diger Fonksiyonlar
        /// </summary>
        /// <returns></returns>
        public static List<string> IlceAdiGetAll()
        {
            var ilceColumn = from i in db.Ilce select i.IlceAdi;
            List<string> ilceList = ilceColumn.ToList();
            return ilceList;
        }

        public static List<string> IlceAdiGetBySehirId(string sehirId)
        {
            var ilceColumn = from i in db.Ilce where i.SehirID == sehirId select i.IlceAdi;
            List<string> ilceList = ilceColumn.ToList();
            return ilceList;
        }

        public static string IlceAdiGetByKullaniciId(int kullaniciId)
        {
            var ilceAdi = (from k in db.KullaniciIletisim where k.KullaniciID == kullaniciId select k.Ilce.IlceAdi).FirstOrDefault();
            return ilceAdi;
        }

        public static int IlceIdGetByIlceAdiAndSehirId(string ilceAdi, string sehirId)
        {
            var i = db.Ilce.
                Where(c => c.IlceAdi == ilceAdi && c.SehirID == sehirId).
                Select(c => c.IlceID).First();
            return i;
        }


    }
}
